package edu.ccut.saturn.basecomponent.database.impl.sqlserver.handler;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import edu.ccut.saturn.basecomponent.database.ISaturnSQL;
import edu.ccut.saturn.basecomponent.database.impl.AbstractSQLHandler;
import edu.ccut.saturn.component.SaturnComponentException;
import edu.ccut.saturn.component.SaturnData;

public class SqlServerDeleteSQLHandler extends AbstractSQLHandler {

	public List<SaturnData> executeQuery(ISaturnSQL saturnSQL,
			Connection connection) throws SaturnComponentException {
		return null;
	}

	public int executeUpdate(ISaturnSQL saturnSQL, Connection connection)
			throws SaturnComponentException {

		if (connection != null) {
			PreparedStatement ps = null;
			try {
				ps = connection.prepareStatement(saturnSQL
						.getSql());
				debug("DELETE_SQL = " + saturnSQL.getSql());
				int i = 1;
				setConditionPrepareStatement(saturnSQL, i, ps);
				int result = ps.executeUpdate();
				ps.clearParameters();
				return result;
			} catch (SQLException e) {
				e.printStackTrace();
			} finally{
				if (ps != null){
					try {
						ps.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
			}
		}
		return 0;
	}
	
	@Override
	protected String getSpecialSqlKey(String typeKey) {
		if ("FLOAT".equalsIgnoreCase(typeKey)){
			typeKey = "DOUBLE";
		}
		return typeKey;
	}	
}